<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="测试点">
              <a-input placeholder="请输入测试点" v-model="queryParam.testPoints"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="产品类型">
              <j-dict-select-tag placeholder="请输入产品类型" v-model="queryParam.carrierType" dictCode="carrier_type"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标准值">
              <a-input placeholder="请输入标准值" v-model="queryParam.standard"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="下限">
                <a-input placeholder="请输入下限" v-model="queryParam.lowerLimit"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="上限">
                <a-input placeholder="请输入上限" v-model="queryParam.upLimit"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="检测时间1">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.detection1_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.detection1_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('报表四')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <report-four-modal ref="modalForm" @ok="modalFormOk"></report-four-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ReportFourModal from './modules/ReportFourModal'
  import { deleteAction, getAction, putAction, postAction, httpAction, downFile, getFileAccessHttpUrl,printAction } from '@/api/manage'

  export default {
    name: 'ReportFourList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ReportFourModal
    },
    data () {
      return {
        description: '报表四管理页面',
        color: '#f9f9f9',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'测试点',
            align:"center",
            dataIndex: 'testPoints',
            fixed:"left",
            customCell: (record, rowIndex) => {
            return {
              style: {
                'background-color': this.color,
              },
            }
          }
          },
          {
            title:'标准值',
            align:"center",
            dataIndex: 'standard',
            fixed:"left",
            customCell: (record, rowIndex) => {
            return {
              style: {
                'background-color': this.color,
              },
            }
          }
          },
          {
            title:'下限',
            align:"center",
            dataIndex: 'lowerLimit',
            fixed:"left",
            customCell: (record, rowIndex) => {
            return {
              style: {
                'background-color': this.color,
              },
            }
          }
          },
          {
            title:'上限',
            align:"center",
            dataIndex: 'upLimit',
            fixed:"left",
            customCell: (record, rowIndex) => {
            return {
              style: {
                'background-color': this.color,
              },
            }
          }
          },
          
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/ch/reportFour/list",
          delete: "/ch/reportFour/delete",
          deleteBatch: "/ch/reportFour/deleteBatch",
          exportXlsUrl: "/ch/reportFour/exportXls",
          importExcelUrl: "ch/reportFour/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        list1:[],
        list:[]
      }
    },
    created() {
    },
    mounted(){
      // this.dataReception();
      this.changeColumns();
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //获取页面一点击的值并调用混入方法里面的自查询
    //   dataReception() {
          
    //       getAction(this.url.list,).then((res) => {
    //       if (res.success) {
            
    //       }
    //     });
    // },
      changeColumns(){
        this.queryParam.carrierId = this.$route.query.text1;
        let carrierId =  this.queryParam.carrierId
        
        getAction(this.url.list,{carrierId}).then((res) => {
          if (res.success) {
            this.list1 = res.result.records || res.result;
            
            this.list = this.list1[0].mapList;
            
            for(let i = 0;i<this.list.length;i++){
          if(this.list[i].value.substring(0,9) == 'detection'){
            
            this.columns.push({
              title:this.list[i].text,
              align:"center",
              dataIndex: "hashMap."+this.list[i].value
            })
          }
          if(this.list[i].value.substring(0,7) == 'reality'){
            
            this.columns.push({
              title:this.list[i].text,
              align:"center",
              dataIndex: "hashMap."+this.list[i].value
            })
          }
          if(this.list[i].value.substring(0,7) == 'deviate'){
            
            this.columns.push({
              title:this.list[i].text,
              align:"center",
              dataIndex: "hashMap."+this.list[i].value
            })
          }
        }
        this.columns.push({
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
            })
            this.searchQuery();
          }
          })
        
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'testPoints',text:'测试点',dictCode:''})
        fieldList.push({type:'string',value:'standard',text:'标准值',dictCode:''})
        fieldList.push({type:'string',value:'lowerLimit',text:'下限',dictCode:''})
        fieldList.push({type:'string',value:'upLimit',text:'上限',dictCode:''})
        fieldList.push({type:'datetime',value:'detection1',text:'检测时间1'})
        fieldList.push({type:'string',value:'reality1',text:'实际1',dictCode:''})
        fieldList.push({type:'string',value:'deviate1',text:'偏离1',dictCode:''})
        fieldList.push({type:'datetime',value:'detection2',text:'检测时间2'})
        fieldList.push({type:'string',value:'reality2',text:'实际2',dictCode:''})
        fieldList.push({type:'string',value:'deviate2',text:'偏离2',dictCode:''})
        fieldList.push({type:'datetime',value:'detection3',text:'检测时间3'})
        fieldList.push({type:'string',value:'reality3',text:'实际3',dictCode:''})
        fieldList.push({type:'string',value:'deviate3',text:'偏离3',dictCode:''})
        fieldList.push({type:'datetime',value:'detection4',text:'检测时间4'})
        fieldList.push({type:'string',value:'reality4',text:'实际4',dictCode:''})
        fieldList.push({type:'string',value:'deviate4',text:'偏离4',dictCode:''})
        fieldList.push({type:'datetime',value:'detection5',text:'检测时间5'})
        fieldList.push({type:'string',value:'reality5',text:'实际5',dictCode:''})
        fieldList.push({type:'string',value:'deviate5',text:'偏离5',dictCode:''})
        fieldList.push({type:'datetime',value:'detection6',text:'检测时间6'})
        fieldList.push({type:'string',value:'reality6',text:'实际6',dictCode:''})
        fieldList.push({type:'string',value:'deviate6',text:'偏离6',dictCode:''})
        fieldList.push({type:'datetime',value:'detection7',text:'检测时间7'})
        fieldList.push({type:'string',value:'reality7',text:'实际7',dictCode:''})
        fieldList.push({type:'string',value:'deviate7',text:'偏离7',dictCode:''})
        fieldList.push({type:'datetime',value:'detection8',text:'检测时间8'})
        fieldList.push({type:'string',value:'reality8',text:'实际8',dictCode:''})
        fieldList.push({type:'string',value:'deviate8',text:'偏离8',dictCode:''})
        fieldList.push({type:'datetime',value:'detection9',text:'检测时间9'})
        fieldList.push({type:'string',value:'reality9',text:'实际9',dictCode:''})
        fieldList.push({type:'string',value:'deviate9',text:'偏离9',dictCode:''})
        fieldList.push({type:'datetime',value:'detection10',text:'检测时间10'})
        fieldList.push({type:'string',value:'reality10',text:'实际10',dictCode:''})
        fieldList.push({type:'string',value:'deviate10',text:'偏离10',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>